package me.lc.linklink.core;

import me.lc.linklink.R;
import android.app.Activity;
import android.content.SharedPreferences;

import com.wiyun.engine.nodes.CharMap;
import com.wiyun.engine.opengl.Texture2D;
import com.wiyun.engine.sound.AudioManager;
import com.wiyun.engine.types.WYRect;
import com.wiyun.engine.utils.ResolutionIndependent;

/**
 * 控制游戏整体参数，加载各种游戏资源
 * 
 * @author Administrator
 * 
 */
public class GameSystem {
	public static Activity AndroidContext;

	public static SharedPreferences SharedSettings;

	public static final String WiGameAppKey = "5923b1052049d744";

	public static final String WiGameSecretKey = "ZgyUWrbFPDLvUXq2eq9H83b8WGtqsk5X";

	public static int ComboTimeout = 3;

	/**
	 * 屏幕宽度
	 */
	public static float Screen_Width = 0;

	/**
	 * 屏幕高度
	 */
	public static float Screen_Height = 0;

	/**
	 * 屏幕实际高度
	 */
	public static float Screen_ActuallyHeight = 0;

	/**
	 * 游戏行数
	 */
	public static int GameRows = 8;

	/**
	 * 游戏列数
	 */
	public static int GameColumns = 7;

	/**
	 * 游戏元素大小
	 */
	public static final int BLOCK_SIZE = 60;

	/**
	 * 游戏两边留空
	 */
	public static final int Margin_Side = 30;

	/**
	 * 连连看元素起始高度
	 */
	public static float Start_Height = 0;

	public static int Star3Score = 7000;
	public static int Star2Score = 4500;

	public static final int Time_Stage_Index = 7;

	public static Texture2D llkTex;
	public static Texture2D bgTex;
	public static Texture2D buttomBarTex;
	public static Texture2D selectorTex;
	public static Texture2D cloudTex;
	public static Texture2D gameBackgroundTex;
	public static Texture2D processBgTex;
	public static Texture2D processForeTex;
	public static Texture2D numberTex;
	public static Texture2D finderTex;
	public static Texture2D comboTex;
	public static Texture2D readyGoTex;
	public static CharMap charMap;

	public static Texture2D mainMenuBgTex;
	public static Texture2D mainMenuBgMoving1Tex;
	public static Texture2D mainMenuBgMoving2Tex;
	public static Texture2D menuBGTex;
	public static Texture2D btnHelpTex;

	public static Texture2D stageMenuBgTex;
	public static Texture2D stageButtonTex;
	public static Texture2D stageLockerTex;

	public static Texture2D loseBgTex;
	public static Texture2D winBgTex;

	public static Texture2D btnContinueTex;
	public static Texture2D btnBuyTex;
	public static Texture2D pauseBGTex;

	public static Texture2D helpTex;

	public static Texture2D star1Tex;
	public static Texture2D star2Tex;
	public static Texture2D star3Tex;

	public static Texture2D gameUpTex;
	public static Texture2D gameDownTex;
	public static Texture2D gameLeftTex;
	public static Texture2D gameRightTex;
	public static Texture2D gameNormalTex;
	public static Texture2D gameLeftRightTex;
	public static Texture2D gameUpDownTex;

	public static void loadAllResource() {
		initSetting();
		loadTexture();
		initCharMap();
		loadSound();
		GameMap.init();
	}

	private static void loadSound() {
		AudioManager.preloadBackgroundMusic(R.raw.background);
		AudioManager.preloadEffect(R.raw.clear);
		AudioManager.preloadEffect(R.raw.click);
		AudioManager.preloadEffect(R.raw.lose);
		AudioManager.preloadEffect(R.raw.readygo);
		AudioManager.preloadEffect(R.raw.win);
		AudioManager.preloadEffect(R.raw.click);
		AudioManager.preloadEffect(R.raw.buy);
	}

	private static void initSetting() {
		SharedSettings = AndroidContext.getPreferences(Activity.MODE_PRIVATE);
		StageManager.instance.initStageInfo();
		StageManager.instance.initGameParams();
		ShopManager.instance.init();
	}

	private static void initCharMap() {
		charMap = CharMap.make();
		// charMap.autoRelease();
		charMap.mapChar(WYRect.make(0, 0, ResolutionIndependent.resolveDp(20),
				ResolutionIndependent.resolveDp(25)), '0');
		charMap.mapChar(WYRect.make(ResolutionIndependent.resolveDp(20), 0,
				ResolutionIndependent.resolveDp(10),
				ResolutionIndependent.resolveDp(25)), '1');
		charMap.mapChar(WYRect.make(ResolutionIndependent.resolveDp(30), 0,
				ResolutionIndependent.resolveDp(21),
				ResolutionIndependent.resolveDp(25)), '2');
		charMap.mapChar(WYRect.make(ResolutionIndependent.resolveDp(51), 0,
				ResolutionIndependent.resolveDp(21),
				ResolutionIndependent.resolveDp(25)), '3');
		charMap.mapChar(WYRect.make(ResolutionIndependent.resolveDp(72), 0,
				ResolutionIndependent.resolveDp(21),
				ResolutionIndependent.resolveDp(25)), '4');
		charMap.mapChar(WYRect.make(ResolutionIndependent.resolveDp(93), 0,
				ResolutionIndependent.resolveDp(21),
				ResolutionIndependent.resolveDp(25)), '5');
		charMap.mapChar(WYRect.make(ResolutionIndependent.resolveDp(114), 0,
				ResolutionIndependent.resolveDp(21),
				ResolutionIndependent.resolveDp(25)), '6');
		charMap.mapChar(WYRect.make(ResolutionIndependent.resolveDp(135), 0,
				ResolutionIndependent.resolveDp(21),
				ResolutionIndependent.resolveDp(25)), '7');
		charMap.mapChar(WYRect.make(ResolutionIndependent.resolveDp(156), 0,
				ResolutionIndependent.resolveDp(21),
				ResolutionIndependent.resolveDp(25)), '8');
		charMap.mapChar(WYRect.make(ResolutionIndependent.resolveDp(177), 0,
				ResolutionIndependent.resolveDp(21),
				ResolutionIndependent.resolveDp(25)), '9');

	}

	private static void loadTexture() {
		llkTex = Texture2D.makePNG(R.drawable.r60);
		selectorTex = Texture2D.makePNG(R.drawable.selector);
		cloudTex = Texture2D.makePNG(R.drawable.cloud_animation);
		gameBackgroundTex = Texture2D.makeJPG(R.drawable.maingb);
		processBgTex = Texture2D.makePNG(R.drawable.process_bg);
		processForeTex = Texture2D.makePNG(R.drawable.process_fore);
		numberTex = Texture2D.makePNG(R.drawable.number);
		buttomBarTex = Texture2D.makePNG(R.drawable.buttom_bar);
		finderTex = Texture2D.makePNG(R.drawable.finder);
		comboTex = Texture2D.makePNG(R.drawable.combo);
		readyGoTex = Texture2D.makePNG(R.drawable.ready_go);

		mainMenuBgTex = Texture2D.makeJPG(R.drawable.main);
		mainMenuBgMoving1Tex = Texture2D.makePNG(R.drawable.moving1);
		mainMenuBgMoving2Tex = Texture2D.makePNG(R.drawable.moving2);

		menuBGTex = Texture2D.makePNG(R.drawable.mainmenu_bg);
		btnHelpTex = Texture2D.makePNG(R.drawable.button_help);

		stageMenuBgTex = Texture2D.makePNG(R.drawable.stage_bg);
		stageButtonTex = Texture2D.makePNG(R.drawable.stagebutton);
		stageLockerTex = Texture2D.makePNG(R.drawable.lock);

		loseBgTex = Texture2D.makePNG(R.drawable.lose_bg);
		winBgTex = Texture2D.makePNG(R.drawable.win_bg);

		btnContinueTex = Texture2D.makePNG(R.drawable.button_continue);
		btnBuyTex = Texture2D.makePNG(R.drawable.button_buy);
		pauseBGTex = Texture2D.makePNG(R.drawable.pause_shop_bg);

		helpTex = Texture2D.makeJPG(R.drawable.help);

		star1Tex = Texture2D.makePNG(R.drawable.star1);
		star2Tex = Texture2D.makePNG(R.drawable.star2);
		star3Tex = Texture2D.makePNG(R.drawable.star3);

		gameUpTex = Texture2D.makePNG(R.drawable.game_up);
		gameDownTex = Texture2D.makePNG(R.drawable.game_down);
		gameLeftTex = Texture2D.makePNG(R.drawable.game_left);
		gameRightTex = Texture2D.makePNG(R.drawable.game_right);
		gameNormalTex = Texture2D.makePNG(R.drawable.game_normal);
		gameLeftRightTex = Texture2D.makePNG(R.drawable.game_leftright);
		gameUpDownTex = Texture2D.makePNG(R.drawable.game_updown);
		gameLeftRightTex.loadTexture();
		gameUpDownTex.loadTexture();
		gameUpTex.loadTexture();
		gameDownTex.loadTexture();
		gameLeftTex.loadTexture();
		gameRightTex.loadTexture();
		gameNormalTex.loadTexture();
		star1Tex.loadTexture();
		star2Tex.loadTexture();
		star3Tex.loadTexture();
		helpTex.loadTexture();
		pauseBGTex.loadTexture();
		btnContinueTex.loadTexture();
		btnBuyTex.loadTexture();
		stageLockerTex.loadTexture();
		stageButtonTex.loadTexture();
		gameBackgroundTex.loadTexture();
		stageMenuBgTex.loadTexture();
		comboTex.loadTexture();
		finderTex.loadTexture();
		processBgTex.loadTexture();
		processForeTex.loadTexture();
		numberTex.loadTexture();
		llkTex.loadTexture();
		selectorTex.loadTexture();
		cloudTex.loadTexture();
		buttomBarTex.loadTexture();
		menuBGTex.loadTexture();
		btnHelpTex.loadTexture();
		readyGoTex.loadTexture();
		loseBgTex.loadTexture();
		winBgTex.loadTexture();
	}
}
